﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPIWareMVVM.ViewModels;
using DataAccess;
using System.Windows;

namespace SPIWareMVVM.Views.Commands
{
    public class AddNewPressMachineCommand : BaseCommand
    {
        public AddNewPressMachineCommand(BaseViewModel sender) : base(sender) { }

        public override void Execute(object parameter)
        {
            //MaterialList list = (MaterialList)parameter;
            //if (list != null)
            //{
            //    list.lbMaterials.ItemsSource = null;

            //    Part newPart = ApplicationData.NewPart();
            //    ((ApplicationViewModel)_sender).SelectedMaterial = newPart;

            //    list.lbMaterials.ItemsSource = ApplicationData.ocParts;
            //    list.lbMaterials.SelectedItem = newPart;
            //    list.spPartInformation.DataContext = newPart;

            //    if (list.Visibility == System.Windows.Visibility.Collapsed) list.Visibility = System.Windows.Visibility.Visible;
            //}
            PressMachineList list = (PressMachineList)parameter;
            if (list != null)
            {
                //list.lbPressMachine.ItemsSource = null;
                MachinePress press = ApplicationData.NewMachinePress();

                //list.dpPressMachineEdit.DataContext = ApplicationData.ocMachinePresses;

                ApplicationData.ClearAllExcept(new List<Type> { typeof(MachinePress) });
                if (mainWindow == null) mainWindow = (Window1)Window.GetWindow((PressMachineList)list);
                mainWindow.HideLists();
                
                list.lbPressMachine.ItemsSource = ApplicationData.ocMachinePresses;
                list.lbPressMachine.SelectedItem = press;
                if (list.Visibility == System.Windows.Visibility.Collapsed) list.Visibility = System.Windows.Visibility.Visible;
            }
        }
    }
}
